
cc.Class({
    extends: cc.Component,

    properties: {
        //游戏管理器.
        game:{
            default: null,
            serializable: false
        },
        flyTime:0,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        //是否被收集：避免重复触发.
        this.isCollected = false;
    },

    start () {

    },

    // update (dt) {},

    onCollisionEnter: function(other, self){
        if(other.tag == 1){
            //被收集:飞向Icon.
            this.collected();
        }
    },

    //被收集.
    collected(){
        if(this.isCollected){
            return;
        }
        this.isCollected = true;
        //改变父物体.
        this.node.parent = this.game.canvasNode;
        this.node.position = this.node.position.sub(this.game.cameraNode.position);
        //动作结束执行.
        var finished = cc.callFunc(function () {
            this.game.collectCoin();
            this.node.destroy();
        }, this);
        var myAction = cc.sequence(cc.moveTo(this.flyTime, this.game.timeIconNode.position), finished);
        this.node.runAction(myAction);
    },
});
